﻿package org.display.graphic
{
	import flash.display.Sprite;
	import flash.events.*;
	import flash.filesystem.File;
	import flash.text.TextField;
	import flash.utils.Timer;
	
	import mx.controls.Alert;
	
	import org.data.Global;
	import org.utils.ElementControl;

	public class EventSquare extends Sprite
	{

		var eventName:String
		var classPath:String
		
		var rollOverColor:uint
		var rollOurColor:uint
		
		public function EventSquare(classSpace:String,rollOverColor:uint,rollOurColor:uint)
		{
			this.rollOurColor=rollOurColor
			this.rollOverColor=rollOverColor
			
			this.buttonMode=true
			this.useHandCursor=true

			this.addEventListener(MouseEvent.MOUSE_UP,mouseEvent)	
				
			this.addEventListener(MouseEvent.ROLL_OVER,mouseEvent)	
				
			this.addEventListener(MouseEvent.ROLL_OUT,mouseEvent)	
				
			 eventName= classSpace.split(".")[classSpace.split(".").length-1]
				
			 classPath=Global.workspace+"\\"+classSpace.replace(/\./gis,"\\")+".as"
				 
			//classPath=classPath.replace("\\display\\","\\commands\\")
				 
			 draw(rollOurColor)
			 
				 
		}
		
		
		function mouseEvent(e:MouseEvent){
			
			switch(e.type){
				
			case MouseEvent.MOUSE_UP:
				
			trace(classPath)
			
			try{
				var file:File = File.desktopDirectory.resolvePath(classPath);
				file.openWithDefaultApplication();
			}catch(e:Error){Alert.show("路径不存在:"+classPath)}
			
			break
			
			case MouseEvent.ROLL_OVER:

			var tt:TextField=new TextField()
			tt.text=eventName
			tt.border=true
			tt.autoSize="left"
			tt.background=true
			
			stage.addChild(tt)
			
			tt.x=stage.mouseX+20
			tt.y=stage.mouseY+20
			
			draw(rollOverColor)
			
			
			break
			
			
			case MouseEvent.ROLL_OUT:
				
			ElementControl.cleanObjByType(TextField,stage)
			
			draw(rollOurColor)
				
			break

			
			}
			

		}
		
		function draw(color:uint){
		
			graphics.clear()
			graphics.lineStyle(1,0x000000,1)
			graphics.beginFill(color,1)
			graphics.drawEllipse(0,0,20,20)
			graphics.endFill()
		
		}
		
		
		
	}
}